﻿using ChoMy.Helpers;
using ChoMy.Models;
using ChoMy.Models.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace ChoMy.Controllers
{
    public class PostController : Controller
    {
        private ChoMyContext db = new ChoMyContext();
        private StringHelper strHp = new StringHelper();

        public ActionResult Details(string postNameId, string groupNameId)
        {
            if (String.IsNullOrWhiteSpace(postNameId) || String.IsNullOrWhiteSpace(groupNameId))
            {
                return RedirectToAction("BadRequest", "Error");
            }

            Post post = db.Posts.FirstOrDefault(x => x.NameId == postNameId && !x.IsDelete);
            PostGroup postGroup = db.PostGroups.FirstOrDefault(x => x.NameId == groupNameId && !x.IsDelete);

            if (post == null || postGroup == null)
            {
                return RedirectToAction("NotFound", "Error");
            }

            ViewBag.PostGroup = postGroup;

            return View(post);
        }

        public ActionResult _MenuRight()
        {
            List<PostGroup> postGroups = db.PostGroups.ToList();

            return PartialView(postGroups);
        }
    }
}